package com.first.agent.service.impl;

import com.first.agent.common.R;
import com.first.agent.dao.ReportDao;
import com.first.agent.dao.impl.ReportDaoImpl;
import com.first.agent.pojo.AdvanceCharge;
import com.first.agent.pojo.AgentCustomer;
import com.first.agent.pojo.Product;
import com.first.agent.pojo.User;
import com.first.agent.service.ReportService;

import java.sql.SQLException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ljc
 * Date: 2022/11/15 11:17
 * Description:
 * Version: V1.0
 */
public class ReportServiceImpl implements ReportService {
    ReportDao reportDao=new ReportDaoImpl();
    R r=new R();
    @Override
    public R findAgentBalance(String start,String end ) {
        try {
            List<User> agentBalance = reportDao.findAgentBalance(start,end);
            if (!agentBalance.toString().equals("[]") ){
                r.setCode(0);
                r.setMsg("查找成功");
                r.setData(agentBalance);
            }else {
                r.setCode(500);
                r.setMsg("查找数据为空");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(505);
            r.setMsg("服务器开小差了");
        }
        return  r;
    }

    @Override
    public R findCharge(String start, String end) {
        try {
            List<AdvanceCharge> charge = reportDao.findCharge(start, end);
            if (!charge.toString().equals("[]") ){
                r.setCode(0);
                r.setMsg("查找成功");
                r.setData(charge);
            }else {
                r.setCode(500);
                r.setMsg("查找数据为空");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(505);
            r.setMsg("服务器开小差了");
        }
        return  r;
    }

    @Override
    public R findAgent(String start, String end) {
        try {
            List<AdvanceCharge> agent = reportDao.findAgent(start, end);
            if (!agent.toString().equals("[]") ){
                r.setCode(0);
                r.setMsg("查找成功");
                r.setData(agent);
            }else {
                r.setCode(500);
                r.setMsg("查找数据为空");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(505);
            r.setMsg("服务器开小差了");
        }
        return  r;
    }

    @Override
    public R findProduct(String start, String end) {
        try {
            List<Product> product = reportDao.findProduct(start, end);
            int num=1;
            for (Product product1 : product) {
                product1.setNum(num++);
            }
            if (!product.toString().equals("[]") ){
                r.setCode(0);
                r.setMsg("查找成功");
                r.setData(product);
            }else {
                r.setCode(500);
                r.setMsg("查找数据为空");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(505);
            r.setMsg("服务器开小差了");
        }
        return r;
    }
}
